﻿using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using Dcms.BLL;
using Dcms.Model;
using System.Web.Security;

/// <summary>
/// adminMag 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class adminMag : System.Web.Services.WebService
{


    public adminMag()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }


    /// <summary>
    /// 设置管理帐号
    /// </summary>
    /// <param name="adminID">旧的帐号ID</param>
    /// <param name="adminPass">帐号密码</param>
    /// <param name="newAdminID">新的帐号ID</param>
    /// <returns></returns>
    /// 查询一个帐号，如果不存加添加为管理员帐号，如果存在修改为管理员帐号
    [WebMethod]
  
    public bool SetAdmin(string adminID,string adminPass,string newAdminID)
    {
        try
        {
            Dcms_AdminBLL adminbll = new Dcms_AdminBLL();
            Dcms_AdminModel adminmodel = new Dcms_AdminModel();
            adminmodel = adminbll.GetModelByName(adminID);
            if (adminmodel == null)
            {
                adminmodel=new Dcms_AdminModel();
                adminmodel.Admin_Name = newAdminID;
                adminmodel.Admin_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(adminPass, "md5").ToLower();
                adminmodel.Admin_RoleId = 0;
                adminbll.AddModel(adminmodel);
            }
            else
            {
                adminmodel.Admin_Name = newAdminID;
                adminmodel.Admin_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(adminPass, "md5").ToLower();
                adminbll.Update(adminmodel);
            }

            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
     
        //return "Hello World";
    }

}

